/*
 * @Author: 孙旺 741967556@qq.com
 * @Date: 2025-05-10 10:58:34
 * @LastEditors: 孙旺 741967556@qq.com
 * @LastEditTime: 2025-05-10 16:09:54
 * @FilePath: \兴元\尝试\qiankun\secondApp\src\main.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { createApp } from "vue";
import App from "./App.vue";
import {
  renderWithQiankun,
  qiankunWindow,
} from "vite-plugin-qiankun/dist/helper";

let app = null;

const render = (props = {}) => {
  const { container } = props;
  app = createApp(App);
  app.mount(container ? container.querySelector("#app") : "#app");
};

// 独立运行时
if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render();
}

// 作为子应用运行时
renderWithQiankun({
  mount(props) {
    console.log("vue3-vite mount", props);
    render(props);
  },
  bootstrap() {
    console.log("vue3-vite bootstrap");
  },
  unmount(props) {
    console.log("vue3-vite unmount", props);
    app.unmount();
    app = null;
  },
  update(props) {
    console.log("vue3-vite update", props);
  },
});
